// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Security;

public sealed partial class IndexPrivilegesCheck
{
	/// <summary>
	/// <para>
	/// This needs to be set to true (default is false) if using wildcards or regexps for patterns that cover restricted indices.
	/// Implicitly, restricted indices do not match index patterns because restricted indices usually have limited privileges and including them in pattern tests would render most such tests false.
	/// If restricted indices are explicitly included in the names list, privileges will be checked against them regardless of the value of allow_restricted_indices.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("allow_restricted_indices")]
	public bool? AllowRestrictedIndices { get; set; }

	/// <summary>
	/// <para>
	/// A list of indices.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("names")]
	public Elastic.Clients.Elasticsearch.Serverless.Indices Names { get; set; }

	/// <summary>
	/// <para>
	/// A list of the privileges that you want to check for the specified indices.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("privileges")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndexPrivilege> Privileges { get; set; }
}

public sealed partial class IndexPrivilegesCheckDescriptor : SerializableDescriptor<IndexPrivilegesCheckDescriptor>
{
	internal IndexPrivilegesCheckDescriptor(Action<IndexPrivilegesCheckDescriptor> configure) => configure.Invoke(this);

	public IndexPrivilegesCheckDescriptor() : base()
	{
	}

	private bool? AllowRestrictedIndicesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Indices NamesValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndexPrivilege> PrivilegesValue { get; set; }

	/// <summary>
	/// <para>
	/// This needs to be set to true (default is false) if using wildcards or regexps for patterns that cover restricted indices.
	/// Implicitly, restricted indices do not match index patterns because restricted indices usually have limited privileges and including them in pattern tests would render most such tests false.
	/// If restricted indices are explicitly included in the names list, privileges will be checked against them regardless of the value of allow_restricted_indices.
	/// </para>
	/// </summary>
	public IndexPrivilegesCheckDescriptor AllowRestrictedIndices(bool? allowRestrictedIndices = true)
	{
		AllowRestrictedIndicesValue = allowRestrictedIndices;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of indices.
	/// </para>
	/// </summary>
	public IndexPrivilegesCheckDescriptor Names(Elastic.Clients.Elasticsearch.Serverless.Indices names)
	{
		NamesValue = names;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of the privileges that you want to check for the specified indices.
	/// </para>
	/// </summary>
	public IndexPrivilegesCheckDescriptor Privileges(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndexPrivilege> privileges)
	{
		PrivilegesValue = privileges;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AllowRestrictedIndicesValue.HasValue)
		{
			writer.WritePropertyName("allow_restricted_indices");
			writer.WriteBooleanValue(AllowRestrictedIndicesValue.Value);
		}

		writer.WritePropertyName("names");
		JsonSerializer.Serialize(writer, NamesValue, options);
		writer.WritePropertyName("privileges");
		JsonSerializer.Serialize(writer, PrivilegesValue, options);
		writer.WriteEndObject();
	}
}